package com.sjb.stock.controller;

import com.sjb.stock.pojo.entity.SysUser;
import com.sjb.stock.service.impl.UserServiceImpl;
import com.sjb.stock.vo.req.LoginReqVo;
import com.sjb.stock.vo.resp.LoginRespVo;
import com.sjb.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


/**
 * @FileName UserController
 * @Description
 * @Author chm
 * @date 2025/6/21
 **/
@RestController
@RequestMapping("/api")
@Api(tags = "用户接口", value = "/api/**")
public class UserController {
    @Resource
    private UserServiceImpl userServiceImpl;

    /**
     * @param useName
     * @return com.sjb.stock.pojo.entity.SysUser
     * @description: 查找系统用户信息
     * @author chm
     * @date 2025/7/15
     **/
    @ApiOperation("查找系统用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "useName", value = "用户名", required = true, dataType = "String")
    })
    @GetMapping("/user/{useName}")
    public SysUser getUserByUserName(@PathVariable("useName") String useName) {
        return userServiceImpl.getUserByUserName(useName);
    }

    /**
     * @param loginReqVo
     * @return com.sjb.stock.vo.resp.R<com.sjb.stock.vo.resp.LoginRespVo>
     * @description: 登录功能
     * @author chm
     * @date 2025/7/15
     **/
    @ApiOperation("登录功能")
    @PostMapping("/login")
    public R<LoginRespVo> login(@RequestBody LoginReqVo loginReqVo) {
        return userServiceImpl.login(loginReqVo);
    }

    /**
     * @return com.sjb.stock.vo.resp.R<java.util.Map>
     * @description: 生成图片验证码
     * @author chm
     * @date 2025/7/15
     **/
    @ApiOperation("生成图片验证码")
    @GetMapping("/captcha")
    public R<Map> getCaptchaCode() {
        return userServiceImpl.getCaptchaCode();
    }

}
